from django.db import models

# Create your models here.
from django.db import models
from django.conf import settings


class AdminLog(models.Model):
    """管理员操作日志"""
    ACTION_CHOICES = (
        ('user_manage', '用户管理'),
        ('activity_manage', '活动管理'),
        ('system_manage', '系统管理'),
    )

    admin = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name='管理员')
    action = models.CharField(max_length=20, choices=ACTION_CHOICES, verbose_name='操作类型')
    description = models.TextField(verbose_name='操作描述')
    ip_address = models.GenericIPAddressField(verbose_name='IP地址')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='操作时间')

    class Meta:
        db_table = 'admin_logs'
        verbose_name = '管理员日志'
        verbose_name_plural = '管理员日志'
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.admin.username} - {self.get_action_display()}"


class SystemSetting(models.Model):
    """系统设置"""
    key = models.CharField(max_length=100, unique=True, verbose_name='设置键')
    value = models.TextField(verbose_name='设置值')
    description = models.CharField(max_length=200, verbose_name='描述')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'system_settings'
        verbose_name = '系统设置'
        verbose_name_plural = '系统设置'

    def __str__(self):
        return self.key